package com.coordinate.core.kernel.serviceprovider.impl;

import java.io.UnsupportedEncodingException;
import java.util.List;

/*Email Java Mail API*/
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;



import com.coordinate.core.kernel.serviceprovider.EmailServiceProvider;
import com.coordinate.core.kernel.serviceprovider.SmsServiceProvider;
import com.coordinate.core.message.Message;
import com.coordinate.core.transport.Sms;
import com.coordinate.core.type.DeliveryReport;
import com.coordinate.core.type.impl.CUnicodeConverter;
import com.devicemantra.coordinate.tasks.CTask;
import com.devicemantra.coordinate.tasks.CTaskFactory;

public class CSmsServiceProvider extends CServiceProvider implements SmsServiceProvider {

	

	public int send(Message pMsg) 
	{
		int lResult = -1;
	    Sms lSmsMsg;
	    List<String> lList;
	    String lEnglishText,lArabicText;
	    
		if(! (pMsg instanceof Sms))
		{
			System.out.println("Sorry, this message cannot be sent as an SMS, throw Exception");
	        return lResult; 		
		}
		
	    lSmsMsg = (Sms)pMsg;
	    lEnglishText = lSmsMsg.getSmsBody("en");
	    lArabicText = lSmsMsg.getSmsBody("ar");
	    String lText = null;

	    lList = lSmsMsg.getSmsReceipientsList();
	    
	    if(lEnglishText!= null)
	    {
	    for(String lMobileNumber: lList)
        {
	    	CTask lSmsTask = CTaskFactory.createNewSMSTask();
			
	        lSmsTask.setTaskUrl("/SMSTask");
	        lSmsTask.addParameter("mobile_number",lMobileNumber);
	        lSmsTask.addParameter("message",lEnglishText);
	        lSmsTask.addParameter("lang","en");
	        CTaskFactory.addTaskToQueue(lSmsTask);
        }
	    }
	    
	    /*if(lArabicText!= null)
	    {
	    for(String lMobileNumber: lList)
        {
	    	CTask lSmsTask = CTaskFactory.createNewSMSTask();
			
	        lSmsTask.setTaskUrl("/SMSTask");
	        lSmsTask.addParameter("mobile_number",lMobileNumber);
	        lSmsTask.addParameter("message",lText);
	        lSmsTask.addParameter("lang","ar");
	        //CTaskFactory.addTaskToQueue(lSmsTask);
        }
	    }   */
		return 0;
	}
	
	
	
	public List<DeliveryReport> getDeliveryReports(String pUniqueMsgId) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
